@echo off
setlocal enabledelayedexpansion

REM 检查当前脚本路径
set SCRIPT_PATH=%~dp0
REM 设置 Ice 二进制工具路径
set ICE_TOOL=%SCRIPT_PATH%..\..\..\..\public_library\ice-3.7.7\tools\slice2cpp.exe
REM 设置 Ice 文件所在路径
set ICE_FILE_PATH=%SCRIPT_PATH%ice_file
REM 设置输出路径
set OUTPUT_PATH=%SCRIPT_PATH%ice_out

REM 创建输出目录如果不存在
if not exist %OUTPUT_PATH% mkdir %OUTPUT_PATH%

REM 检查 Ice 工具是否存在
if not exist %ICE_TOOL% (
    echo Error: Could not find slice2cpp.exe at %ICE_TOOL%
    pause
    goto :eof
)

REM 循环处理 .ice 文件
for /r "%ICE_FILE_PATH%" %%i in (*.ice) do (
    set ICE_FILE=%%i
    echo Processing file: %%i
    %ICE_TOOL% -I"%ICE_FILE_PATH%" --output-dir="%OUTPUT_PATH%" "%%i"
    if errorlevel 1 (
        echo Failed to process file: %%i
    ) else (
        echo File processed successfully.
    )
)

echo All files processed successfully.

:end
endlocal

pause